package GUI;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.TitledBorder;

import Ctr.CtrVare;
import Model.Format;
import Model.Udlejningstype;
import Model.Vare;
import Model.Vare_Varegenre;
import Model.Varegenre;

/*
 * GUIVare.java
 *
 * Created on 04-05-2011, 10:40:30
 */
/**
 *
 * @author Kim
 */
public class GUIVare extends javax.swing.JPanel
{
	private CtrVare ctrVar;
	private JTextArea textArea;
	
    /** Creates new form GUIVare */
    public GUIVare(JTextArea text)
    {
        initComponents();
        ctrVar = new CtrVare();
        addUdlejningstyper();
        textArea = text;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        
        nulstil = new javax.swing.JButton();
        nulstil.setFont(new Font("Tahoma", Font.PLAIN, 9));
        nulstil.addActionListener(new ActionListener()
        {
        	public void actionPerformed(ActionEvent e)
        	{
        		nulstilAlt();
        	}
        });
        opdater = new javax.swing.JButton();
        opdater.addActionListener(new ActionListener()
        {
        	public void actionPerformed(ActionEvent e)
        	{
//        		ctrVar.updateVare(Integer.parseInt(vareid.getText()), navn.getText(), 10, 15, 080211, type, format)
        	}
        });
        opret = new javax.swing.JButton();
        opret.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent e) {

        			String navn1 = navn.getText();
        			String beskrivelse1 = beskrivelse.getText();
        	    	int rating1=Integer.parseInt(rating.getText());
        			String aldersgruppe1=aldersgruppe.getText();
        	    	String udgivelsesdato1 = udgivelsesdato.getText();
        	    	String udlejningstype1 = udlejningstype.getSelectedItem().toString();
        	    	ArrayList<Varegenre> vgList = new ArrayList<Varegenre>();
        	    	vgList = opretVareGenre();
        	    	ctrVar.createVare(navn1, beskrivelse1, rating1,aldersgruppe1, udgivelsesdato1, udlejningstype1,opretFormater(),vgList);
        	    	Vare v = ctrVar.findVare(navn1);
        	    	vareid.setText(Integer.toString(v.getVareid()));
        	}
        });
        find = new javax.swing.JButton();
        find.setFont(new Font("Tahoma", Font.PLAIN, 11));
        find.addActionListener(new ActionListener()
        {
        	public void actionPerformed(ActionEvent e)
        	{
        	try{	
        		if(!navn.getText().equals(""))
        		{
        			Vare v = ctrVar.findVareNavn((navn.getText()));
        			setVare(v);
        		}
        		else if(!vareid.getText().equals(""))
        		{
        			Vare v = ctrVar.findVareId(Integer.parseInt(vareid.getText()));
        			setVare(v);
        		}
        	}
        	catch(Exception e2)
    		{
    			JOptionPane.showMessageDialog(null, e2, "Error", JOptionPane.ERROR_MESSAGE);
    		}
        	}
        });
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Vare", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14))); // NOI18N
        jPanel1.setToolTipText("null");

        nulstil.setText("Nulstil");

        opdater.setText("Opdater");

        opret.setText("Opret");

        find.setLabel("Find");

        javax.swing.GroupLayout gl_jPanel2 = new javax.swing.GroupLayout(jPanel2);
        gl_jPanel2.setHorizontalGroup(
        	gl_jPanel2.createParallelGroup(Alignment.TRAILING)
        		.addGroup(Alignment.LEADING, gl_jPanel2.createSequentialGroup()
        			.addContainerGap()
        			.addComponent(opret)
        			.addPreferredGap(ComponentPlacement.UNRELATED)
        			.addComponent(find)
        			.addPreferredGap(ComponentPlacement.UNRELATED)
        			.addComponent(nulstil)
        			.addGap(18)
        			.addComponent(opdater)
        			.addContainerGap(49, Short.MAX_VALUE))
        );
        gl_jPanel2.setVerticalGroup(
        	gl_jPanel2.createParallelGroup(Alignment.LEADING)
        		.addGroup(gl_jPanel2.createSequentialGroup()
        			.addContainerGap()
        			.addGroup(gl_jPanel2.createParallelGroup(Alignment.BASELINE)
        				.addComponent(opret)
        				.addComponent(find)
        				.addComponent(nulstil)
        				.addComponent(opdater))
        			.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2.setLayout(gl_jPanel2);
        jPanel4 = new javax.swing.JPanel();
        
                jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Genre", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12)));
                                
                                action = new JCheckBox("Action");
                                
                                adventure = new JCheckBox("Adventure");
                                
                                comedy = new JCheckBox("Comedy");
                                
                                scifi = new JCheckBox("Sci-fi");
                                
                                drama = new JCheckBox("Drama");
                                
                                thriller = new JCheckBox("Thriller");
                                
                                love = new JCheckBox("Love");
                        
                                javax.swing.GroupLayout gl_jPanel4 = new javax.swing.GroupLayout(jPanel4);
                                gl_jPanel4.setHorizontalGroup(
                                	gl_jPanel4.createParallelGroup(Alignment.LEADING)
                                		.addGroup(gl_jPanel4.createSequentialGroup()
                                			.addContainerGap()
                                			.addGroup(gl_jPanel4.createParallelGroup(Alignment.LEADING)
                                				.addComponent(drama)
                                				.addComponent(action))
                                			.addGap(42)
                                			.addGroup(gl_jPanel4.createParallelGroup(Alignment.LEADING)
                                				.addComponent(adventure)
                                				.addComponent(thriller))
                                			.addGap(22)
                                			.addGroup(gl_jPanel4.createParallelGroup(Alignment.LEADING)
                                				.addComponent(love)
                                				.addComponent(comedy))
                                			.addPreferredGap(ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
                                			.addComponent(scifi)
                                			.addGap(54))
                                );
                                gl_jPanel4.setVerticalGroup(
                                	gl_jPanel4.createParallelGroup(Alignment.LEADING)
                                		.addGroup(gl_jPanel4.createSequentialGroup()
                                			.addContainerGap()
                                			.addGroup(gl_jPanel4.createParallelGroup(Alignment.LEADING)
                                				.addComponent(scifi)
                                				.addGroup(gl_jPanel4.createSequentialGroup()
                                					.addGroup(gl_jPanel4.createParallelGroup(Alignment.BASELINE)
                                						.addComponent(adventure)
                                						.addComponent(action))
                                					.addPreferredGap(ComponentPlacement.UNRELATED)
                                					.addGroup(gl_jPanel4.createParallelGroup(Alignment.BASELINE)
                                						.addComponent(thriller)
                                						.addComponent(drama)))
                                				.addGroup(gl_jPanel4.createSequentialGroup()
                                					.addComponent(comedy)
                                					.addPreferredGap(ComponentPlacement.UNRELATED)
                                					.addComponent(love)))
                                			.addGap(23))
                                );
                                jPanel4.setLayout(gl_jPanel4);
        
        JPanel panel = new JPanel();
        panel.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.TOP, null, null));
        jPanel3 = new javax.swing.JPanel();
        dvdcheck = new javax.swing.JCheckBox();
        bluraycheck = new javax.swing.JCheckBox();
        tredcheck = new javax.swing.JCheckBox();
        jLabel13 = new javax.swing.JLabel();
        dvdAntal = new javax.swing.JTextField();
        blurayAntal = new javax.swing.JTextField();
        tredAntal = new javax.swing.JTextField();
        
                jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Platform", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N
                
                        dvdcheck.setText("DVD");
                        
                                bluraycheck.setText("BluRay");
                                
                                        tredcheck.setText("3D");
                                                
                                                        jLabel13.setText("Antal");
                                                        jLabel4 = new javax.swing.JLabel();
                                                        
                                                                jLabel4.setText("Salgspris");
                                                                dvdpris = new javax.swing.JTextField();
                                                                
                                                                bluraypris = new JTextField();
                                                                
                                                                tredpris = new JTextField();
                                                                
                                                                JLabel lblUdlejningstype = new JLabel("Udlejningstype");
                                                                
                                                                udlejningstype = new javax.swing.JComboBox();
                                                                
                                                                
                                                                        javax.swing.GroupLayout gl_jPanel3 = new javax.swing.GroupLayout(jPanel3);
                                                                        gl_jPanel3.setHorizontalGroup(
                                                                        	gl_jPanel3.createParallelGroup(Alignment.LEADING)
                                                                        		.addGroup(gl_jPanel3.createSequentialGroup()
                                                                        			.addGroup(gl_jPanel3.createParallelGroup(Alignment.LEADING)
                                                                        				.addGroup(gl_jPanel3.createSequentialGroup()
                                                                        					.addGap(15)
                                                                        					.addComponent(lblUdlejningstype))
                                                                        				.addGroup(gl_jPanel3.createSequentialGroup()
                                                                        					.addGap(12)
                                                                        					.addGroup(gl_jPanel3.createParallelGroup(Alignment.TRAILING)
                                                                        						.addComponent(dvdcheck, Alignment.LEADING)
                                                                        						.addComponent(tredcheck, Alignment.LEADING)
                                                                        						.addComponent(bluraycheck))))
                                                                        			.addPreferredGap(ComponentPlacement.UNRELATED)
                                                                        			.addGroup(gl_jPanel3.createParallelGroup(Alignment.LEADING)
                                                                        				.addGroup(gl_jPanel3.createSequentialGroup()
                                                                        					.addGroup(gl_jPanel3.createParallelGroup(Alignment.LEADING)
                                                                        						.addComponent(jLabel13, GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)
                                                                        						.addGroup(gl_jPanel3.createParallelGroup(Alignment.LEADING, false)
                                                                        							.addComponent(tredAntal)
                                                                        							.addComponent(blurayAntal)
                                                                        							.addComponent(dvdAntal, GroupLayout.PREFERRED_SIZE, 38, GroupLayout.PREFERRED_SIZE)))
                                                                        					.addPreferredGap(ComponentPlacement.UNRELATED)
                                                                        					.addGroup(gl_jPanel3.createParallelGroup(Alignment.LEADING)
                                                                        						.addComponent(jLabel4)
                                                                        						.addComponent(dvdpris, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE)
                                                                        						.addComponent(bluraypris, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE)
                                                                        						.addComponent(tredpris, GroupLayout.PREFERRED_SIZE, 64, GroupLayout.PREFERRED_SIZE))
                                                                        					.addGap(179))
                                                                        				.addGroup(gl_jPanel3.createSequentialGroup()
                                                                        					.addComponent(udlejningstype, GroupLayout.PREFERRED_SIZE, 192, GroupLayout.PREFERRED_SIZE)
                                                                        					.addContainerGap())))
                                                                        );
                                                                        gl_jPanel3.setVerticalGroup(
                                                                        	gl_jPanel3.createParallelGroup(Alignment.LEADING)
                                                                        		.addGroup(gl_jPanel3.createSequentialGroup()
                                                                        			.addContainerGap()
                                                                        			.addGroup(gl_jPanel3.createParallelGroup(Alignment.TRAILING)
                                                                        				.addGroup(gl_jPanel3.createSequentialGroup()
                                                                        					.addComponent(dvdcheck)
                                                                        					.addPreferredGap(ComponentPlacement.RELATED)
                                                                        					.addComponent(bluraycheck)
                                                                        					.addPreferredGap(ComponentPlacement.RELATED)
                                                                        					.addComponent(tredcheck)
                                                                        					.addGap(13))
                                                                        				.addGroup(gl_jPanel3.createSequentialGroup()
                                                                        					.addGroup(gl_jPanel3.createParallelGroup(Alignment.LEADING)
                                                                        						.addGroup(gl_jPanel3.createSequentialGroup()
                                                                        							.addComponent(jLabel4)
                                                                        							.addGap(12)
                                                                        							.addComponent(dvdpris, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                                                        							.addPreferredGap(ComponentPlacement.RELATED)
                                                                        							.addComponent(bluraypris, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                                                        							.addPreferredGap(ComponentPlacement.RELATED)
                                                                        							.addComponent(tredpris, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                                                        						.addGroup(gl_jPanel3.createSequentialGroup()
                                                                        							.addComponent(jLabel13)
                                                                        							.addGap(12)
                                                                        							.addComponent(dvdAntal, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                                                        							.addPreferredGap(ComponentPlacement.RELATED)
                                                                        							.addComponent(blurayAntal, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                                                        							.addPreferredGap(ComponentPlacement.RELATED)
                                                                        							.addComponent(tredAntal, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
                                                                        					.addPreferredGap(ComponentPlacement.UNRELATED)))
                                                                        			.addGroup(gl_jPanel3.createParallelGroup(Alignment.BASELINE)
                                                                        				.addComponent(lblUdlejningstype)
                                                                        				.addComponent(udlejningstype, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                                                                        			.addContainerGap(19, Short.MAX_VALUE))
                                                                        );
                                                                        jPanel3.setLayout(gl_jPanel3);

        javax.swing.GroupLayout gl_jPanel1 = new javax.swing.GroupLayout(jPanel1);
        gl_jPanel1.setHorizontalGroup(
        	gl_jPanel1.createParallelGroup(Alignment.LEADING)
        		.addGroup(Alignment.TRAILING, gl_jPanel1.createSequentialGroup()
        			.addContainerGap()
        			.addGroup(gl_jPanel1.createParallelGroup(Alignment.TRAILING)
        				.addComponent(panel, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 452, Short.MAX_VALUE)
        				.addComponent(jPanel4, Alignment.LEADING, 0, 0, Short.MAX_VALUE)
        				.addComponent(jPanel2, Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 341, GroupLayout.PREFERRED_SIZE)
        				.addComponent(jPanel3, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 452, Short.MAX_VALUE))
        			.addContainerGap())
        );
        gl_jPanel1.setVerticalGroup(
        	gl_jPanel1.createParallelGroup(Alignment.TRAILING)
        		.addGroup(gl_jPanel1.createSequentialGroup()
        			.addComponent(panel, GroupLayout.PREFERRED_SIZE, 192, GroupLayout.PREFERRED_SIZE)
        			.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        			.addComponent(jPanel3, GroupLayout.PREFERRED_SIZE, 187, GroupLayout.PREFERRED_SIZE)
        			.addPreferredGap(ComponentPlacement.UNRELATED)
        			.addComponent(jPanel4, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE)
        			.addGap(18)
        			.addComponent(jPanel2, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
        			.addGap(31))
        );
        jLabel2 = new javax.swing.JLabel();
        
                jLabel2.setText("Navn");
        jLabel6 = new javax.swing.JLabel();
        
                jLabel6.setText("Rating");
        navn = new javax.swing.JTextField();
        udgivelsesdato = new javax.swing.JTextField();
        rating = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        
                jLabel1.setText("ID: ");
        jLabel8 = new javax.swing.JLabel();
        
                jLabel8.setText("Udg. dato");
        jLabel5 = new javax.swing.JLabel();
        
                jLabel5.setText("Beskrivelse");
        
        beskrivelse = new JTextArea();
        beskrivelse.setText("");
        
        vareid = new JTextField();
        vareid.setColumns(10);
        
        JLabel lblAldersgruppe = new JLabel("Aldersgruppe");
        
        aldersgruppe = new JTextField();
        aldersgruppe.setColumns(10);
        GroupLayout gl_panel = new GroupLayout(panel);
        gl_panel.setHorizontalGroup(
        	gl_panel.createParallelGroup(Alignment.LEADING)
        		.addGroup(gl_panel.createSequentialGroup()
        			.addContainerGap()
        			.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
        				.addGroup(gl_panel.createSequentialGroup()
        					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
        						.addComponent(jLabel1)
        						.addComponent(jLabel2))
        					.addGap(27)
        					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
        						.addComponent(navn, GroupLayout.PREFERRED_SIZE, 126, GroupLayout.PREFERRED_SIZE)
        						.addComponent(vareid, GroupLayout.PREFERRED_SIZE, 126, GroupLayout.PREFERRED_SIZE)))
        				.addGroup(gl_panel.createParallelGroup(Alignment.LEADING, false)
        					.addGroup(gl_panel.createSequentialGroup()
        						.addComponent(jLabel6)
        						.addGap(21)
        						.addComponent(rating))
        					.addGroup(gl_panel.createSequentialGroup()
        						.addComponent(jLabel8)
        						.addPreferredGap(ComponentPlacement.RELATED)
        						.addComponent(udgivelsesdato, GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE)))
        				.addGroup(gl_panel.createSequentialGroup()
        					.addComponent(lblAldersgruppe)
        					.addPreferredGap(ComponentPlacement.RELATED)
        					.addComponent(aldersgruppe, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
        			.addGap(25)
        			.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
        				.addComponent(jLabel5, Alignment.LEADING)
        				.addComponent(beskrivelse, GroupLayout.DEFAULT_SIZE, 206, Short.MAX_VALUE))
        			.addContainerGap())
        );
        gl_panel.setVerticalGroup(
        	gl_panel.createParallelGroup(Alignment.LEADING)
        		.addGroup(gl_panel.createSequentialGroup()
        			.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        			.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING, false)
        				.addGroup(gl_panel.createSequentialGroup()
        					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
        						.addComponent(jLabel1)
        						.addComponent(vareid, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        					.addPreferredGap(ComponentPlacement.RELATED))
        				.addGroup(gl_panel.createSequentialGroup()
        					.addComponent(jLabel5)
        					.addGap(10)))
        			.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
        				.addGroup(gl_panel.createSequentialGroup()
        					.addGap(6)
        					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
        						.addComponent(jLabel2)
        						.addComponent(navn, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        					.addGap(14)
        					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
        						.addComponent(rating, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
        						.addComponent(jLabel6))
        					.addGap(16)
        					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
        						.addComponent(jLabel8)
        						.addComponent(udgivelsesdato, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
        					.addPreferredGap(ComponentPlacement.UNRELATED)
        					.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
        						.addComponent(lblAldersgruppe)
        						.addComponent(aldersgruppe, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
        				.addGroup(gl_panel.createSequentialGroup()
        					.addGap(3)
        					.addComponent(beskrivelse, GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)))
        			.addContainerGap())
        );
        panel.setLayout(gl_panel);
        jPanel1.setLayout(gl_jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        layout.setHorizontalGroup(
        	layout.createParallelGroup(Alignment.LEADING)
        		.addGroup(layout.createSequentialGroup()
        			.addContainerGap()
        			.addComponent(jPanel1, GroupLayout.PREFERRED_SIZE, 484, GroupLayout.PREFERRED_SIZE)
        			.addContainerGap(57, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
        	layout.createParallelGroup(Alignment.LEADING)
        		.addGroup(layout.createSequentialGroup()
        			.addContainerGap()
        			.addComponent(jPanel1, GroupLayout.PREFERRED_SIZE, 580, GroupLayout.PREFERRED_SIZE)
        			.addContainerGap(104, Short.MAX_VALUE))
        );
        this.setLayout(layout);
    }
    
    private void addUdlejningstyper()
    {
    	ArrayList<Udlejningstype> list = new ArrayList<Udlejningstype>();
    	list = ctrVar.findUdlejningstyper();
    	for(Udlejningstype u : list)
    	{
    		udlejningstype.addItem(u.getTypenavn());
    	}
    }
    
    private ArrayList<Format> opretFormater()
    {
    	ArrayList<Format> list = new ArrayList<Format>();
    	if(dvdcheck.isSelected()==true)
    	{
    		Format f = new Format();
    		f.setMedie("DVD");
    		f.setAntal(Integer.parseInt(dvdAntal.getText()));
    		f.setPris(Double.parseDouble(dvdpris.getText()));
    		list.add(f);
    	}
    		if(bluraycheck.isSelected()==true)
    		{
    			Format f = new Format();
        		f.setMedie("BluRay");
        		f.setAntal(Integer.parseInt(blurayAntal.getText()));
        		f.setPris(Double.parseDouble(bluraypris.getText()));
        		list.add(f);
    		}
    			if(tredcheck.isSelected()==true)
    			{
    				Format f = new Format();
    	    		f.setMedie("3D");
    	    		f.setAntal(Integer.parseInt(tredAntal.getText()));
    	    		f.setPris(Double.parseDouble(tredpris.getText()));
    	    		list.add(f);
    			}
    	return list;
    }
    
    private ArrayList<Varegenre> opretVareGenre()
    {
    	ArrayList<Varegenre> vgList = new ArrayList<Varegenre>();
    	if(action.isSelected()==true){
    		vgList.add(ctrVar.findVareGenreNavn("Action"));
    	}
    	if(adventure.isSelected()==true)
    	{
    		vgList.add(ctrVar.findVareGenreNavn("Adventure"));
    	}
    	if(comedy.isSelected()==true)
    	{
    		vgList.add(ctrVar.findVareGenreNavn("Comedy"));
    	}
    	return vgList;
    }
    
    public void nulstilAlt()
    {
    	vareid.setText("");
    	navn.setText("");
		rating.setText("");
		udgivelsesdato.setText("");
		aldersgruppe.setText("");
		beskrivelse.setText("");

		dvdcheck.setSelected(false);
		dvdAntal.setText("");
		dvdpris.setText("");
		bluraycheck.setSelected(false);
		blurayAntal.setText("");
		bluraypris.setText("");
		tredcheck.setSelected(false);
		tredAntal.setText("");
		tredpris.setText("");
		udlejningstype.setSelectedIndex(0);
		
		action.setSelected(false);
		adventure.setSelected(false);
		comedy.setSelected(false);
		scifi.setSelected(false);
		drama.setSelected(false);
		thriller.setSelected(false);
		love.setSelected(false);
    }
    
    private void setVare(Vare v)
    {
    	vareid.setText(Integer.toString(v.getVareid()));
		navn.setText(v.getNavn());
		rating.setText(Integer.toString(v.getRating()));
		udgivelsesdato.setText(v.getUdgivelsesdato());
		beskrivelse.setText(v.getBeskrivelse());
		aldersgruppe.setText(v.getAldersgruppe());
		udlejningstype.setSelectedItem(v.getUdlejningstype().getTypenavn());
		for(Format f : v.getFormater())
		{
			if(f.getMedie().equals("DVD"))
			{
				dvdcheck.setSelected(true);
				dvdAntal.setText(Integer.toString(f.getAntal()));
				dvdpris.setText(Double.toString(f.getPris()));
			}
			if(f.getMedie().equals("BluRay"))
			{
				bluraycheck.setSelected(true);
				blurayAntal.setText(Integer.toString(f.getAntal()));
				bluraypris.setText(Double.toString(f.getPris()));
			}
			if(f.getMedie().equals("3D"))
			{
				tredcheck.setSelected(true);
				tredAntal.setText(Integer.toString(f.getAntal()));
				tredpris.setText(Double.toString(f.getPris()));
			}
		}
		for(Vare_Varegenre vvg : v.getVvg())
		{
			if(vvg.getG().getGenre().equals("Action"))
			{
				action.setSelected(true);
			}
			if(vvg.getG().getGenre().equals("Adventure"))
			{
				adventure.setSelected(true);
			}
			if(vvg.getG().getGenre().equals("Comedy"))
			{
				comedy.setSelected(true);
			}
		}
    }
    
    
    private javax.swing.JButton nulstil;
    private javax.swing.JButton opdater;
    private javax.swing.JButton opret;
    private javax.swing.JButton find;
    private javax.swing.JCheckBox dvdcheck;
    private javax.swing.JCheckBox bluraycheck;
    private javax.swing.JCheckBox tredcheck;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JTextField dvdAntal;
    private javax.swing.JTextField blurayAntal;
    private javax.swing.JTextField tredAntal;
    private javax.swing.JTextField navn;
    private javax.swing.JTextField dvdpris;
    private javax.swing.JTextField rating;
    private javax.swing.JTextField udgivelsesdato;
    private JTextField bluraypris;
    private JTextField tredpris;
    private JCheckBox action;
    private JCheckBox adventure;
    private JCheckBox comedy;
    private JCheckBox scifi;
    private JCheckBox drama;
    private JCheckBox thriller;
    private JCheckBox love;
    private javax.swing.JComboBox udlejningstype;
    private JTextField vareid;
    private JTextArea beskrivelse;
    private JTextField aldersgruppe;
}
